package servlets;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.UserDao;

import bean.User;

public class LoginServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		String username = req.getParameter("admin");
		String password = req.getParameter("password");

		User user = new UserDao().exists(username, password);
		HttpSession session = req.getSession();
		
		if(user != null) {
			session.setAttribute("user", user);
			resp.sendRedirect("chuliServlet?choice_id=1&message=");
		}else {
			resp.sendRedirect("loginFail.jsp");
		}
	}
}
